Programming With QuickTime Sprites

| Previous | Chapter Contents | Chapter Top | Next |

Creating the Movie, Sprite Track, and Media

Listing 1-6 shows a code fragment from the sample code QTWiredSprites.c . This sample code, which is available in Appendix C, illustrates how you can create a new movie file that calls a sample code function, AddSpriteTrackToMovie , which is responsible for creating a sprite track and adding it to the movie.

Listing 6 Creating a sprite track movie

// Create a QuickTime movie containing a wired sprites track.

OSErr QTWired_CreateWiredSpritesMovie (void)
{
    short                   myResRefNum = 0;
    Movie                   myMovie = NULL;
    Track                   myTrack;
    Media                   myMedia;
    StandardFileReply       myReply;
    QTAtomContainer         mySample = NULL;
    QTAtomContainer         myActions = NULL;
    QTAtomContainer         myBeginButton, myPrevButton, myNextButton,
                                myEndButton;
    QTAtomContainer         myPenguinOne, myPenguinTwo,
                                myPenguinOneOverride;
    QTAtomContainer         myBeginActionButton, myPrevActionButton,
                                myNextActionButton, myEndActionButton;
    QTAtomContainer         myPenguinOneAction, myPenguinTwoAction;
    RGBColor                myKeyColor;
    Point                   myLocation;
    short                   isVisible, myLayer, myIndex, myResID, i,
                                myDelta;
    Boolean                 hasActions;
    long                    myFlags = createMovieFileDeleteCurFile |
                                createMovieFileDontCreateResFile;
    OSType                  myType = FOUR_CHAR_CODE('none');
    UInt32                  myFrequency;
    QTAtom                  myEventAtom;
    long                    myLoopingFlags;
    ModifierTrackGraphicsModeRecord     myGraphicsMode;
    OSErr                   myErr = noErr;

    // create a new movie file and set its controller type
    // ask the user for the name of the new movie file
    StandardPutFile("\pSprite movie file name:", "\pSprite.mov",
                    &myReply);
    if (!myReply.sfGood)
        goto bail;

    // create a movie file for the destination movie
    myErr = CreateMovieFile(&myReply.sfFile, FOUR_CHAR_CODE('TVOD'), 0,
                myFlags, &myResRefNum, &myMovie);
    if (myErr != noErr)
        goto bail;
    
    // select the "no controller" movie controller
    myType = EndianU32_NtoB(myType);
    SetUserDataItem(GetMovieUserData(myMovie), &myType, sizeof(myType),
                        kUserDataMovieControllerType, 1);

The following code fragment from AddSpriteTrackToMovie ( Listing 1-7 ) creates a new track and new media, and creates an empty key frame sample. AddSpriteTrackToMovie then calls BeginMediaEdits ( Listing 1-9 ) to prepare to add samples to the track's media.

Listing 7 Creating a track and media

// create the sprite track and media
    
    myTrack = NewMovieTrack(myMovie, ((long)kSpriteTrackWidth << 16),
                        ((long)kSpriteTrackHeight << 16), kNoVolume);
    myMedia = NewTrackMedia(myTrack, SpriteMediaType,
                            kSpriteMediaTimeScale, NULL, 0);

    // create a new, empty key frame sample
    myErr = QTNewAtomContainer(&mySample);
    if (myErr != noErr)
        goto bail;

    myKeyColor.red = 0xffff;                        // white
    myKeyColor.green = 0xffff;
    myKeyColor.blue = 0xffff;

© 1998 Apple Computer, Inc.

| Previous | Chapter Contents | Chapter Top | Next |